package com.shujia.getdata;

import java.io.*;
import java.util.ArrayList;

public class PutData {
    public static void putDataToFile(String path) throws IOException {
        File metaData = new File(path);
        int index = 0;
        BufferedReader br = new BufferedReader(new FileReader(metaData));
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\workspace\\ideaProjects\\bigdata27-mypro\\hadoop\\data\\put\\data-0000" + index));
        String line ;

        ArrayList<String> list = new ArrayList<>();

        int size=0;
        while ((line = br.readLine()) != null){
              size++;
              list.add(line);
              if(size==140){
                  for(int i=128*index;i<128*(index+1);i++){
                      bw.write(list.get(i));
                      bw.newLine();
                      bw.flush();
                  }
                  index++;
                  bw = new BufferedWriter(new FileWriter("E:\\workspace\\ideaProjects\\bigdata27-mypro\\hadoop\\data\\put\\data-0000" + index));
                  size =12;
              }

        }
        br.close();
        for (int i =128*index;i<list.size();i++){
            bw.write(list.get(i));
            bw.newLine();
            bw.flush();
        }
        bw.close();

    }
}
